<?php include("include.php");?>
<?php
$jobid = $_GET['jid'];
$job = job::getJobById($jobid);
$ressources = ressourcetype::getAllRessourceType();
$currentSolution = jobsolution::getJobSolutionByJobId($jobid);
?>
<script type="text/javascript" src="js/jobconfig.js"></script>
<h1>Configuring Quarls for <?php echo $job->getTitle();?></h1>
<div id="contentPane">

<div id="jobConfig">
<form action="configureJobAction.php" method="post" id="configureJobForm">
<input type="hidden" name="jobid" value="<?php echo $job->getId();?>" />
<table>
	<tr><td colspan="5"><h3>Select Category  & Type of Quarks</h3></td></tr>
    <tr>
    <td>
	    <center><table>
			<tr>
                <td>
                <select name="ressourcetype_id" id="ctlRessourceType" size="2">
                <?php echo ressourcetype::generateOption($job->getRessourceType()->getId())?>
                </select>
                </td>
                <td>
                        <img src="images/next-icon.png" />
                </td>          
                <td>
                <select name="ressourceext_id" id="ctlRessouceExt" size="2">
                <?php if($job->getRessourceExt()->getId() != 0){
						echo ressourceext::generateOptionByRessourceTypeById($job->getRessourceType()->getId()
								,$job->getRessourceExt()->getId());		
				}?>
                </select>
                </td>   
	    </tr>
    	</table></center>
    </td>
    </tr>
    <tr><td id="spacer"></td></tr>
    <tr>
    	<td >
        	<h3>Possible Solutions</h3>
        </td> 
     </tr>
     <tr>
         <td >
         <div id="solutionPane">         
		<?php if(($currentSolution->num_rows)>0){
			?>         
            <input id="NUM_SOLUTION" type="hidden" name="NUM_SOLUTION" value="<?php echo $currentSolution->num_rows;?>" />       
			<?php while($row = $currentSolution->fetch_assoc()){
				$temp = new jobsolution($row['id'],$row['job_id'],$row['name'],$row['value']);
			?>
             <div id="<?php echo $temp->getValue();?>">
			 <?php echo $temp->getValue();?>. <input type="text" id="solution_<?php echo $temp->getValue();?>" 
             name="solution_<?php echo $temp->getValue();?>" value="<?php echo $temp->getName();?>"/>
             <?php if($temp->getValue() >2){
					echo "<img onclick=\"javascript:removeSolution('".$temp->getValue()."');\" src=\"images/remove-icon.png\">";
			 }?>
             <br /></div>
			 <?php }?>
        <?php }else{?>
             <input id="NUM_SOLUTION" type="hidden" name="NUM_SOLUTION" value="2" />          
             <div id="1">1. <input type="text" id="solution_1" name="solution_1" /><br /></div>
             <div id="2">2. <input type="text" id="solution_2" name="solution_2" /><br /></div>
         <?php }?>
          <div><img onclick="javascript:addSolution();" src="images/add-solution.png" /></div>
            </div> 
         </td>
     </tr>
     <tr>
     	<td style="text-align:center;" >
        	<img onclick="javascript:document.getElementById('configureJobForm').submit();" src="images/save.png" />
        </td>
     </tr>
</table>
        </form>
</div>
</div>
<script type="text/javascript" charset="utf-8">
	$.ajaxSetup ({  
        cache: false  
    });
	
	var loadUrl = "select.php";
	$("select#ctlRessourceType").change(function(){
		$("select#ctlRessouceExt").load(loadUrl,"id="+$(this).val());
	});
</script>
<?php include("includes/footer.php");?>